/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.srcptit.trainning.giangnd.btvn2;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

/**
 *
 * @author GIANG
 */
public class B2 {
    public static void chuanhoa(String s) throws IOException{
        BufferedWriter bf;
        bf= new BufferedWriter(new FileWriter("Data/B2OUT.txt"));
        int sotu=0;
        char []s1=new char[100];
        int k=0;
        for(int i=0;i<s.length();i++){
            if(s.charAt(i)!=' ') {
                s1[k++]=s.charAt(i);
            if(s.charAt(i+1)==' ')
                s1[k++]=' ';
            }
        s1[k]=0;
        }
        System.out.println(s1);
        for(int i=0;i<k;i++)
            if((s1[i]!=' '&&s1[i+1]==' ')||(s1[i]!=' '&&s1[i+1]==0)) sotu++;
        System.out.println("So tu la "+sotu);
        bf.write(sotu);
        bf.close();
    }
    public static void main(String[] args) throws FileNotFoundException, IOException {
        String s=null;
        BufferedReader br=new BufferedReader(new FileReader("Data/B2.txt"));
        while(br.ready()== true){
            s=br.readLine();
        }
        System.out.println("Doc file dc");
        System.out.println(s);
        chuanhoa(s);
    }
}

